package com.yfyszk.kingbird.controller;

import com.yfyszk.kingbird.common.entity.Role;
import com.yfyszk.kingbird.common.redis.RedisUtils;
import com.yfyszk.kingbird.common.result.ApiResult;
import com.yfyszk.kingbird.common.utils.PageInfo;
import com.yfyszk.kingbird.common.utils.PageUtils;
import com.yfyszk.kingbird.common.utils.R;
import com.yfyszk.kingbird.feign.OrderFeignClient;
import com.yfyszk.kingbird.service.IMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user")
@Api("用户服务")
@CrossOrigin
public class UserController {
    @Autowired
    private RedisUtils redisUtils;
    @Autowired
    private OrderFeignClient orderFeignClient;
    /*  @Autowired
      private CouponFeignService couponFeignService;*/
    @Autowired
    private IMemberService memberService;
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @ApiOperation("会员服务batch1接口")
    @GetMapping(value = "/batch1")
    public String batch1(HttpServletRequest request) {
        List<Object[]> batchArgs = new ArrayList<Object[]>();
        batchArgs.add(new Object[]{"小明", 21});
        batchArgs.add(new Object[]{"小红", 22});
        batchArgs.add(new Object[]{"露西", 23});
        String sql = "insert into person (name,age) values (?,?)";
        jdbcTemplate.batchUpdate(sql, batchArgs);
        return "ok";
    }

    /*SpringBoot RestFul风格API接口开发
     * @author wgc
     *@date 2020/12/19 0019 16:24
     * @param pageInfo
     * @param userCode
     * @return com.yfyszk.kingbird.common.utils.R
     */
    @ApiOperation("会员服务listzdyPage接口")
    @RequestMapping("/listzdyPage/{userCode}")
    public R listzdyPage(PageInfo pageInfo, @PathVariable("userCode") String userCode) {
        // redisUtils.lock("15555");
        //redisUtils.set("166","2");
         
        log.info("userCode:{}", userCode);
        PageUtils page = memberService.listzdyPage(pageInfo);
        //调用订单系统
        R r = orderFeignClient.findeOrderByUserId("111");
        System.out.println(r + "------");
        return R.ok().setData(page);
    }
    @ApiOperation("会员服务接口")
    @RequestMapping("/wgctest")
    public ApiResult wgctest() {
        ApiResult apiResult = orderFeignClient.findeOrderByUserIdTest("3333");
        System.out.println(apiResult);
        return apiResult;
    }

}
